<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css"
        integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
        crossorigin="anonymous"></script>

    <link rel="stylesheet" href="./css/bootstrap-table.css">
    <script src="./js/bootstrap-table.js"></script>
    <script src="./js/bootstrap-table-zh-CN.js"></script>

    <style>
        * {
            padding: 5px;

        }

        .a h5 {

            display: inline-block;

        }

        #one {
            border: thin solid #c3d7ea;

        }

        #two {
            margin-top: 10px;
            border: thin solid #c3d7ea;
        }

        #table {
            margin-top: 10px;
            border: thin solid #c3d7ea;
        }
    </style>
</head>

<body>

    <div id="one">



        <div class="a">
            <h5>筛选搜索</h5>
            <form class="navbar-form navbar-right">
                <input id="back" type="reset">
                <button id="search" type="button" class=" btn-default-bzdd" style="background-color: aqua">查询搜索</button>
            </form>
        </div>

        <form action="form_action.asp" method="get">
            输入搜索: <input id="searchtext" type="text" placeholder="订单编号" />
            收货人: <input type="text" placeholder="收货人姓名/手机号码" />
        </form>
        <form action="form_action.asp" method="get">
            提交时间:
            <input type="date" name="birthday" placeholder="请选择时间">
            订单状态:
            <select>
                <option >已完成</option>
                <option>未完成</option>
                <option>正在进行中</option>

            </select>
        </form>
        <form action="form_action.asp" method="get">
            订单分类:
            <select>
                <option>1</option>
            </select>
            订单来源:
            <select>
                <option>1</option>
            </select>
        </form>
    </div>




    <div id="two">数据列表</div>
    <table id="table"></table>

</body>
<script>
    $("#back").click(() => {
        $.ajax({
            success: function (res) {
                $('#search-text').val("");
                refresh();
            }
        })
    })
    function refresh(data) {
        if (data == undefined) {
            $.ajax({
                url: "http://192.168.96.193:8033/order/load",
                success: function (res) {
                    $('#table').bootstrapTable("load", res);
                }
            })
        } else {
            $('#table').bootstrapTable("load", data);
        }

    }
    window.operateEvents = {

        // 删除按钮
        "click #del": function (e, value, row, index) {
            $.ajax({
                url: "http://192.168.96.193:8033/order/del?id=" + row.orderId,
                type: "post",
                success: function (res) {
                    refresh();
                }
            })
        },
        "click #salea": function (e, value, row, index) {
            
            $.ajax({
                url: "http://192.168.96.193:8033/order/selectbyorderid?orderId=" + row.orderId,
                type: "get",
                success: function (res) {
                    console.log(res);
parent.tablechange(e)
                }
            })
        },
    }
    // $(() => {
    //     $("#salea").click((e) => {
    //         parent.tablechange(e)
    //     })
    // })
    // function myFunction() {
    //     parent.tablechange(e)
    //     // window.location.href = './saleinfo.html';

    // }

    $('#table').bootstrapTable({
        url: "http://192.168.96.193:8033/order/load",
        pageNumber: 1, //初始化加载第一页
        pagination: true,//是否分页
        sidePagination: 'client',//server:服务器端分页|client：前端分页
        pageSize: 5,//单页记录数
        pageList: [5, 10],//可选择单页记录数
        columns: [
            {
                field: 'checked',
                checkbox: true,
            }, {
                field: 'id',
                title: '编号'
            }, {
                field: 'orderId',
                title: '订单编号'
            }, {
                field: 'time',
                title: '提交时间'
            }, {
                field: 'userName',
                title: '用户账号'
            }, {
                field: 'orderprice',
                title: '订单金额'
            }, {
                field: 'stateofpay',
                title: '支付状态'
            }, {
                field: 'orderstate',
                title: '订单状态'
            }, {
                field: 'operate',
                title: '操作',
                width: '150px',
                align: 'center',
                events: 'operateEvents',
                formatter: function (value, row, index) {
                    return [

                        '<a ><button class="saleinfo" id="salea" onclick="set()">查看订单</button></a>',
                        '<button id="del">删除订单</button>',
                    ].join('');
                }

            }],
        data: []
    })
    //搜索按钮事件
    $("#search").click(() => {
        console.log("1")
        $.ajax({
            url: "http://192.168.96.193:8033/order/selectbyorderid",
            type: "get",
            data: {
                orderId: $("#searchtext").val()
            },
            success: function (res) {
                console.log("111")
                refresh(res)
            }
        })
    })
    function set(){
        if (window.localStorage) { 
        //存储变量的值 
            localStorage.name = event.target.parentElement.parentElement.parentElement.children[2].innerText; 
            console.log(event.target.parentElement.parentElement.parentElement.children[2].innerText)
            location.href = './saleinfo.html'; 
            
        } else { 
            alert("NOT SUPPORT"); 
        }
    }
</script>

</html>